<?php
class Admin_Model_DbTable_interest extends Zend_Db_Table_Abstract
{
	 protected $_name = 'hae_interest';
	 protected $_sequence=true;
     protected $_primary='id';
	public function getinterest($id)
	{
	    $id = (int)$id;
	    $row = $this->fetchRow('id=' . $id);
		if(!$row)
		{ 
			throw  new Exception("Could not find row {$id}");
		}
		return $row->toArray();
	}
	public function getallinterest()
	{
		$select = $this->select();
		$select->setIntegrityCheck(false);
		$select->from($this->_name,"*");
		$select->join('hae_bdd_country', 'hae_bdd_country.id ='.$this->_name.'.countryId', 'name_en as country');
		$select->join('hae_bdd_region', 'hae_bdd_region.id ='.$this->_name.'.regionId', 'name_en as region');
		$select->join('hae_bdd_city', 'hae_bdd_city.id ='.$this->_name.'.cityId', 'name_en as city');
		$select->join('hae_spot', 'hae_spot.id ='.$this->_name.'.spotId', 'name_en as spot');
		
		
		return $this->fetchAll($select);
	}
	public function addinterest($title_vi,$title_en,$title_ja,$title_cn,$title_fr,$desc_vi,$desc_en, $desc_ja, $desc_cn, $desc_fr, $image, $countryId, $regionId, $cityId, $spotId, $lati, $longti, $priority, $status)
	{
		$data = array(
		'title_vi'   => $title_vi,
		'title_en'   => $title_en,
		'title_ja'   => $title_ja,
		'title_cn'   => $title_cn,
		'title_fr'   => $title_fr,
		'desc_vi' => $desc_vi,
		'desc_en' => $desc_en,
		'desc_ja' => $desc_ja,
		'desc_cn' => $desc_cn,
		'desc_fr' => $desc_fr,
		'image'   => $image,
		'countryId'=>$countryId,
		'regionId' =>$regionId,
		'cityId'  =>$cityId,
		'spotId' =>  $spotId,
		'lati' => $lati,
		'longti' => $longti,
		'priority'=>$priority,
		'status'  =>$status,
		);
		$this->insert($data);
	}
	public function updateinterest($id,$title_vi,$title_en,$title_ja,$title_cn,$title_fr,$desc_vi, $desc_en, $desc_ja, $desc_cn, $desc_fr, $image, $countryId, $regionId, $cityId, $spotId, $lati, $longti, $priority, $status)
	{
		
		$data = array(
		'title_vi'   => $title_vi,
		'title_en'   => $title_en,
		'title_ja'   => $title_ja,
		'title_cn'   => $title_cn,
		'title_fr'   => $title_fr,
		'desc_vi' => $desc_vi,
		'desc_en' => $desc_en,
		'desc_ja' => $desc_ja,
		'desc_cn' => $desc_cn,
		'desc_fr' => $desc_fr,
		'image'   => $image,
		'countryId'=>$countryId,
		'regionId' =>$regionId,
		'cityId'  =>$cityId,
		'spotId' =>  $spotId,
		'lati' => $lati,
		'longti' => $longti,
		'priority'=>$priority,
		'status'  =>$status,
		);
		$this->update($data, 'id = '. (int)$id);
	}
	public function deleteinterest($id)
    {
        return $this->delete('id =' . (int)$id);
    }
    public function changestatus($id,$status)
    {
    	$data = array(
    			'status' => $status,
    	);
    	$this->update($data, 'id = '. (int)$id);
    }
 	public function findinterest($title, $countryId, $regionId)
    {
    	
    	$select=$this->select();
    	
    	if ($title!=NULL)
    	{
			$select->where("`hae_interest`.title_en like '".$title."' OR `hae_interest`.title_vi like  '".$title."' OR `hae_interest`.title_ja like '".$title."' OR `hae_interest`.title_cn like '".$title."' OR `hae_interest`.title_fr like'".$title."'");
    	}
    	if ($countryId!=0)
    	{
			$select->where("`hae_interest`.countryId = ?",$countryId);
    	}
    	
    	if ($regionId!=0)
    	{
			$select->where("`hae_interest`.regionId = ?",$regionId);
    	}
    	
    	$select->setIntegrityCheck(false);
		$select->from($this->_name,"*");
		$select->join('hae_bdd_country', 'hae_bdd_country.id ='.$this->_name.'.countryId', 'name_en as country');
		$select->join('hae_bdd_region', 'hae_bdd_region.id ='.$this->_name.'.regionId', 'name_en as region');
		$select->join('hae_bdd_city', 'hae_bdd_city.id ='.$this->_name.'.cityId', 'name_en as city');
		$select->join('hae_spot', 'hae_spot.id ='.$this->_name.'.spotId', 'name_en as spot');
    	return $this->fetchAll($select);
    }
    
}
?>